package com.front;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.admin.sys.base.module.extend.web.BaseController;
import com.admin.sys.base.entity.ResultInfo;
import com.admin.sys.base.module.office.entity.SysOffice;
import com.admin.sys.base.module.office.service.SysOfficeService;
import com.admin.sys.utils.admin.StringUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *【部门信息】页面接口
 */
@RestController
@RequestMapping("/api/sysOffice")
public class ApiOfficeController extends BaseController {

    @Autowired
    private SysOfficeService sysOfficeService;

    /**
     * 【部门信息】根据条件分页查询
     * @param page
     * @param sysOffice
     * @return
     */
    @RequestMapping("/getPage")
    public ResultInfo getPage(Page<SysOffice> page, SysOffice sysOffice) {
        IPage<SysOffice> iPage = sysOfficeService.getPage(page, sysOffice);
        return ResultInfo.ok("获取分页成功", iPage);
    }

    @RequestMapping("/getTreePage")
    public ResultInfo getTreePage(Page<SysOffice> page, SysOffice sysOffice) {
        IPage<SysOffice> iPage = sysOfficeService.getPage(page,sysOffice);
        List<SysOffice> treeList = sysOfficeService.getOfficeChildren(iPage.getRecords());
        iPage.setRecords(treeList);
        return ResultInfo.ok("获取分页成功", iPage);
    }

    /**
     * 【部门信息】根据条件查询
     * @param sysOffice
     * @return
     */
    @RequestMapping("/getList")
    public ResultInfo getList(SysOffice sysOffice) {
        List<SysOffice> list = sysOfficeService.getList(sysOffice);
        return ResultInfo.ok("获取列表成功", list);
    }

    /**
     * 【部门信息】根据id查询
     * @param id
     * @return
     */
    @RequestMapping("/get")
    public ResultInfo get(String id) {
        SysOffice sysOffice = sysOfficeService.get(id);
        return ResultInfo.ok("获取对象成功", sysOffice);
    }

    /**
     * 获取部门树
     * @return
     */
    @RequestMapping("/getOfficeTree")
    public ResultInfo getOfficeTree(SysOffice sysOffice) {
        List<SysOffice> root = sysOfficeService.getList(sysOffice);
        List<SysOffice> treeList = sysOfficeService.getOfficeChildren(root);
        return ResultInfo.ok("获取列表成功", treeList);
    }

}



